package zuoye0515;

/**
 * 主板
 * 
 * @author Y
 *
 */
public class MainCard {
	private String name;
	private CPU cpu;
	private Memory mem;
	private USB[] bs = new USB[6];

	/**
	 * 主板命名
	 * 
	 * @param name
	 */
	public MainCard(String name) {
		super();
		this.name = name;
	}

	/**
	 * 安装CPU
	 * 
	 * @param c
	 */
	public void installCPU(CPU c) {
		cpu = c;
	}

	/**
	 * 安装储存
	 * 
	 * @param m
	 */
	public void installMemory(Memory m) {
		mem = m;
	}

	/**
	 * 安装USB小插件
	 * 
	 * @param u
	 */
	public void installUSB(USB u) {
		for (int a = 0; a < bs.length; a++) {
			if (bs[a] == null) {
				bs[a] = u;
				return;
			}
		}
	}

	/**
	 * 准备运行
	 */
	public void start() {
		System.out.println(name + "的主板准备开始运行");
		for (int b = 0; b < bs.length; b++) {
			if (bs[b] != null) {
				bs[b].start();
			}
		}
	}

	/**
	 * 工作中...
	 */
	public void work() {
		System.out.println(name + "的主板正在运行");
		System.out.println("CPU开始:");
		cpu.function();
		System.out.println("内存开始:");
		mem.work();
		for (int b = 0; b < bs.length; b++) {
			if (bs[b] != null) {
				bs[b].work();
			}
		}
	}

	/**
	 * 停止工作
	 */
	public void stop() {
		System.out.println(name + "的主板停止运行");
		for (int b = 0; b < bs.length; b++) {
			if (bs[b] != null) {
				bs[b].stop();
			}
		}
	}

}
